package com.wman.lib.fragment;

import android.content.Intent;
import android.view.View;

import com.wman.lib.R;
import com.wman.lib.delegate.TabHomeFragmentDelegate;
import com.wman.lib.entity.TextLableBean;
import com.wman.lib.utils.callback.JsonCallback;
import com.wman.sheep.adapter.BaseRecyclerAdapter;
import com.wman.sheep.adapter.RecyclerHolder;
import com.wman.sheep.common.base.BaseEvent;
import com.wman.sheep.common.utils.ToastUtil;
import com.wman.sheep.mvp.base.BaseFragment;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

/**
 * Name     youcai
 * Anthor   wman
 * Time     2019/08/18 0018 23:57
 * Describe 描述
 */
public class TabHomeFragment extends BaseFragment<TabHomeFragmentDelegate> implements
        View.OnClickListener {

    private Intent mIntent;

    private JsonCallback mJsonCallback;

    @Override
    protected Class<TabHomeFragmentDelegate> getDelegateClass() {
        return TabHomeFragmentDelegate.class;
    }

    @Override
    protected void bindEventListener() {
        super.bindEventListener();

        mIntent = getActivity().getIntent();

        RecyclerView recyclerView = mViewDelegate.get(R.id.recyclerView);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setNestedScrollingEnabled(false);

        List<TextLableBean> lableBeans = new ArrayList<>();
        lableBeans.add(new TextLableBean("房屋年限", "是否提供原始税票"));
        lableBeans.add(new TextLableBean("是否提供原始税票", "不提供"));
        lableBeans.add(new TextLableBean("房屋年限", "是否提供原始税票"));
        lableBeans.add(new TextLableBean("是否提供原始税票", "不提供"));
        lableBeans.add(new TextLableBean("房屋年限", "是否提供原始税票"));
        lableBeans.add(new TextLableBean("是否提供原始税票", "不提供"));
        lableBeans.add(new TextLableBean("房屋年限", "是否提供原始税票"));
        lableBeans.add(new TextLableBean("是否提供原始税票", "不提供"));
        lableBeans.add(new TextLableBean("房屋年限", "是否提供原始税票"));
        lableBeans.add(new TextLableBean("是否提供原始税票", "不提供"));

        BaseRecyclerAdapter adapter = new BaseRecyclerAdapter(recyclerView, lableBeans, R.layout.item_lable_text) {
            @Override
            public void convert(RecyclerHolder holder, Object item, int position) {
                TextLableBean bean = (TextLableBean) item;
                holder.setText(R.id.tv_key, bean.getKey() + "");
                holder.setText(R.id.tv_value, bean.getValue() + "");
            }
        };
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onNoDoubleClick(View v) {
        Intent intent;
        switch (v.getId()) {
            case R.id.ll_feedback:
                ToastUtil.showTextToast("DEBUG");
                break;
        }
    }

    public void reload() {
    }

    @Override
    public void onStart() {
        super.onStart();
        if (!EventBus.getDefault().isRegistered(this)) {//加上判断
            EventBus.getDefault().register(this);//事件订阅者注册,订阅者为  HouseManageActivity
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (EventBus.getDefault().isRegistered(this)) {//加上判断
            EventBus.getDefault().unregister(this);//反注册EventBus
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(BaseEvent event) {
    }
}
